home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bplus11.zip / BPLUS.H < prev    next >
C/C++ Source or Header  |  1989-01-24  |  4KB  |  102 lines

  1.  
  2. /*  bplus.h - data structures and constants  */
  3.  
  4.  
  5. /* the next two lines delete the 'pascal' and 'cdecl' keywords
  6.    to make the source compile on an ANSI compiler.
  7. */
  8. #ifndef    MSC        /* not Microsoft C */
  9. #define cdecl
  10. #define pascal
  11. #endif            /* MSC */
  12.  
  13. /* the following checks are to define things frequently not in
  14.    UNIX compilers, since they are recent ANSI additions.
  15. */
  16. #ifndef SEEK_SET
  17. #define SEEK_SET    0
  18. #endif
  19. #ifndef O_BINARY
  20. #define O_BINARY    0
  21. #endif
  22.  
  23. #if    defined(ANSI_C) | defined(MSC) | defined(M_XENIX)
  24. #define Param(x) x
  25. #else
  26. #define Param(x) ()
  27. #endif    /* ANSI or PCC style decls */
  28.  
  29. #define IX_OK       1
  30. #define IX_FAIL     0
  31. #define EOIX       (-2)
  32. #define MAXKEY      100
  33. #define NUM_BUFS    8
  34. #define MAX_LEVELS  8
  35. #define IXB_SIZE    1024
  36. #define IXB_SPACE  (IXB_SIZE - sizeof(short) - sizeof(long) * 2)
  37.  
  38. typedef long RECPOS;
  39.  
  40. typedef struct                    /*  entry structure in index        */
  41.   {  RECPOS   idxptr;             /*  points to lower index level     */
  42.      RECPOS   recptr;             /*  points to data record           */
  43.      char     key[MAXKEY];        /*  start of record key             */
  44.   }  ENTRY;
  45.  
  46. typedef struct                    /*  index record format             */
  47.   {  RECPOS   brec;               /*  position in index file          */
  48.                                   /*  or location of next free block  */
  49.      short    bend;               /*  first unused block location     */
  50.      RECPOS   p0;                 /*  points to next level            */
  51.      char     entries[IXB_SPACE]; /*  here are the key entries        */
  52.   }  BLOCK;
  53.  
  54. typedef struct                    /*  disk file info                  */
  55.   {  RECPOS   ff;                 /*  location of first free block    */
  56.      short    nl;                 /*  number of index levels          */
  57.   }  IX_DISK;
  58.  
  59. typedef struct                    /*  memory buffer pool of indx blks */
  60.   {  short    dirty;              /*  true if changed                 */
  61.      short    handle;             /*  index file handle               */
  62.      short    count;              /*  number of times referenced      */
  63.      BLOCK    mb;
  64.   }  MEMBLOCK;
  65.  
  66. typedef struct
  67.   {  MEMBLOCK     cache [ NUM_BUFS ];
  68.   }  IX_BUFFER;
  69.  
  70. typedef struct                    /*  in-memory index descriptor      */
  71.   {  short    ixfile;
  72.      short    level;              /*  level in btree                  */
  73.      short    duplicate;          /*  no duplicate keys if 0          */
  74.      struct
  75.        {  RECPOS    cblock;       /*  position in index file          */
  76.           short     coffset;      /*  current offset within block     */
  77.        }  pos [ MAX_LEVELS ];
  78.      BLOCK    root;               /*  root index record               */
  79.      IX_DISK  dx;
  80.   }  IX_DESC;
  81.  
  82. /* a few system procedure types here */
  83. extern long filelength(), lseek(), tell();
  84. extern char *mktemp();
  85. extern int read(), write(), open(), close();
  86. extern void exit(), memcpy();
  87.  
  88. /* ================ external interface ================ */
  89. int cdecl open_index Param((char *,IX_DESC *, int));
  90. int cdecl close_index Param((IX_DESC *));
  91. int cdecl make_index Param((char *,IX_DESC *, int));
  92. int cdecl first_key Param((IX_DESC *));
  93. int cdecl last_key Param((IX_DESC *));
  94. int cdecl next_key Param((ENTRY *, IX_DESC *));
  95. int cdecl prev_key Param((ENTRY *, IX_DESC *));
  96. int cdecl find_key Param((ENTRY *, IX_DESC *));
  97. int cdecl add_key Param((ENTRY *, IX_DESC *));
  98. int cdecl locate_key Param((ENTRY *, IX_DESC *));
  99. int cdecl delete_key Param((ENTRY *, IX_DESC *));
  100. int cdecl find_exact Param((ENTRY *, IX_DESC *));
  101. int cdecl find_1stkey Param((ENTRY *, IX_DESC *));
  102.